/**
 * Created by 黄智超 on 2016/7/6.
 * email:362768225@qq.com
 */

//加载模块
var express = require('express');
var app = express();
var mongoose = require('mongoose');                     // mongoose for mongodb
var morgan = require('morgan');             // 在控制台打印请求 (express4)
var bodyParser = require('body-parser');    // 从HTML POST拉取信息 (express4)
var methodOverride = require('method-override'); // 模拟 DELETE 和 PUT (express4)

//配置
var db =require('./config/database');
mongoose.connect(db.url);     // 链接本地 mongoDB database

app.use(express.static(__dirname + '/public'));
app.use(morgan('dev'));                                         // 在console打印每个请求
app.use(bodyParser.urlencoded({'extended':'true'}));            // parse application/x-www-form-urlencoded
app.use(bodyParser.json());                                     // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(methodOverride());

//加载路由
require('./app/routes')(app);


// 监听  ======================================
app.listen(8080);
console.log("App在8080端口监听！");